/*****************************************************************************/
/*                                                                           */
/*    Domino Operation System System Specific Module                         */
/*                                                                           */
/*    Copyright (C) 2013 Laszlo Arvai                                        */
/*                                                                           */
/*    ------------------------------------------------------------------   */
/*    HTTP request/response handling                                         */
/*****************************************************************************/

#ifndef __netHTTP_h
#define __netHTTP_h

///////////////////////////////////////////////////////////////////////////////
// Includes
#include <krnlTypes.h>
#include <krnlString.h>

///////////////////////////////////////////////////////////////////////////////
// Constants
#define netHTTP_MAX_URL_LENGTH 128
#define netHTTP_STATUS_OK 200

///////////////////////////////////////////////////////////////////////////////
// Types

// HTTP request type
typedef enum
{
	HTTPRQ_Put,
	HTTPRQ_Get,
	HTTPRQ_Post
} HTTPRequestType;

// Request body type
typedef enum
{
	HTTPRBT_None,
	HTTPRBT_JSON,
	HTTPRBT_Binary
} HTTPRequestBodyType;

// Accept body type
typedef enum
{
	HTTPABT_None,
	HTTPABT_JSON,
	HTTPABT_Binary
} HTTPAcceptBodyType;

// HTTP request information
typedef struct
{
	HTTPRequestType Request;
	dosChar URL[netHTTP_MAX_URL_LENGTH];
	dosDWord* ContentLength;
	dosDWord* CRC;
	dosChar Host[netHTTP_MAX_URL_LENGTH];
	HTTPRequestBodyType RequestBodyType;
	HTTPAcceptBodyType AcceptBodyType;

} netHTTPRequestInfo;


///////////////////////////////////////////////////////////////////////////////
// Function prototypes
void netHTTPURLToHost(netHTTPRequestInfo* inout_request);
dosStringLength netCreateHTTPHeader(dosString out_buffer, dosStringLength in_buffer_length, netHTTPRequestInfo* in_request);
dosBool netParseHTTPHeader(dosString in_buffer, dosStringLength in_buffer_length, dosWord* out_status_code, dosConstString in_expected_header_keys[], dosString out_header_values[], dosString in_value_string_buffer, dosStringLength in_value_buffer_length);

#endif
